import { Component } from '@angular/core';
import { NavController,IonicPage } from 'ionic-angular';
import { Http} from '@angular/http';

@IonicPage()
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  // 接收数据用
  listData: Object;
  public addressCard=[
    {"title" : "自己有地址","content" :"中禄帮您高效代办窗口关系取证快递","btnText" : "立即咨询"},
    {"title" : "自己无地址","content" :"中禄提供稳定地址后期财务专业服务","btnText" : "立即咨询"},
  ];
  public contactList=[
    {"title" : "在线咨询","src" :"http://pgt.zoosnet.net/LR/Chatpre.aspx?id=PGT44148991&lng=cn",
    "imgSrc":"../../assets/imgs/zx.png"},
    {"title" : "电话咨询","src" :"http://pgt.zoosnet.net/LR/Chatpre.aspx?id=PGT44148991&lng=cn",
      "imgSrc":"../../assets/imgs/phone.png"},
  ];
  public registerList = [
    {"id":1,"imgurl" : "../../assets/imgs/hmIcon.png","content" :"核名"},
    {"id":2,"imgurl" : "../../assets/imgs/ziliao_icon@2x.png","content" :"提交资料"},
    {"id":3,"imgurl" : "../../assets/imgs/gongshang_icon@2x.png","content" :"工商登记"},
    {"id":4,"imgurl" : "../../assets/imgs/zhizhao_icon@2x.png","content" :"领取执照"},
  ];
  //定义用于登录的Login对象，属性默认值为空，双向绑定获得
  login: { username: string, phone: string } = {
    username: '',
    phone: '',
  };
  constructor(public navCtrl: NavController, private http : Http) {
    let elements = document.querySelectorAll(".tabbar");
    if(elements != null) {
      Object.keys(elements).map((key) => {
        elements[key].style.display ='none';
      });
    }
  }

  isNull(str) {
    if(str === "" || str == undefined)
      return true;
    var regu = "^[ ]+$";
    var re = new RegExp(regu);
    return re.test(str);
  }
  checkMobile(str) { //写一个判断函数
    var re = /^1\d{10}$/ //正则表达式
    if(re.test(str)) { //判断字符是否是11位数字
      return true;
    } else {
      return false;
    }
  }
  getDataFromURL(){
    if(this.isNull(this.login.phone) || !this.checkMobile(this.login.phone)){//判断是否符合手机格式，并且不为空
      return;
    }
    this.http.post("http://test.360jizhang.com:28800/api/official/user/operate",
      {
        phone: this.login.phone, username: this.login.username
      })
      .subscribe(
        (val) => {
          console.log("POST call successful value returned in body",
            val);
        },
        response => {
          console.log("POST call in error", response);
        },
        () => {
          console.log("The POST observable is now completed.");
        });
  }
  ionViewDidLoad() {
    // 网络请求
    /*this.http.request('http://jsonplaceholder.typicode.com/photos')
      .subscribe((res: Response) => {
        this.listData = res.json();
      });*/
  }


}
